package com.example.grpc.client.rpc;

import io.grpc.stub.AbstractStub;
public abstract class EndpointGrpcClient<T extends AbstractStub<T>> extends AbstractEndpointGrpcClient<T> {
    public static final int DEFAULT_GRPC_SERVICE_PORT = 20153;
    protected Endpoint serviceEndPoint;
    
    public EndpointGrpcClient(GrpcChannelManager channelManager) {
        super(channelManager);
    }
    
    protected abstract String provideServiceName();
    
    protected int provideServicePort() {
        return DEFAULT_GRPC_SERVICE_PORT;
    }
    
    protected String provideServiceHost() {
        return "localhost";
    }
    
    @Override
    protected final Endpoint provideEndpoint() {
        if (this.serviceEndPoint == null) {
            this.serviceEndPoint = Endpoint.of(
                provideServiceName(), 
                provideServicePort(), 
                provideServiceHost()
            );
        }
        return this.serviceEndPoint;
    }
}
